﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;


namespace mates_viz
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>

    public partial class Window1 : Window
    {

        UIVizualization Viz;
        stateManager stateMgr;
        soapClient client;

        public Window1()
            : base()
        {
            InitializeComponent();

        }

        // To use Loaded event put Loaded="WindowLoaded" attribute in root element of .xaml file.
        private void WindowLoaded(object sender, EventArgs e)
        {
            Viz = new UIVizualization(vizCanvas);
            client = new soapClient();
            stateMgr = new stateManager(Viz, client);

            if (!client.doLogin("jeff", "jeff123")) return;

            Console.WriteLine("Getting loc guesses...");
            if (!client.getLocGuesses()) return;
            foreach (soapClient.locGuess guess in client.locGuesses)
                Console.WriteLine("  " + guess.loc.Name + "source: " + guess.source + " score: " + guess.score.ToString("0.00"));
            stateManager.matesLoc firstLoc = client.locGuesses[0].loc;

            Console.WriteLine("Getting locs nearby first loc guess...");
            if (!client.getNearbyLocs((float)firstLoc.Latitude, (float)firstLoc.Longitude)) return;
            foreach (stateManager.matesLoc nearbyloc in client.locsNearby)
                Console.WriteLine("  " + nearbyloc.Name + " " + nearbyloc.Distance.ToString("0.0") + " ft");

            Console.WriteLine("Setting location as first loc...");
            if (!client.setLocation(firstLoc.ID )) return;

            Console.WriteLine("Updating state ...");

            stateMgr.Update();

            Console.WriteLine("Logging out...");
            if (!client.doLogout()) return;
        
            //stateMgr.AddUser(new stateManager.matesUser("B14", 2));

            //stateMgr.AddUser(new stateManager.matesUser("2", 0));

            //stateMgr.AddUser(new stateManager.matesUser("I", 1));

        }

        // Sample event handler:  
        private void AddClicked(object sender, RoutedEventArgs e)
        {
            stateMgr.AddUser(new stateManager.matesUser(this.username.Text, Convert.ToInt32(this.loc.Text)));
            //try
            //{
            //    stateMgr.AddUser(new stateManager.matesUser(this.username.Text, Convert.ToInt32(this.loc.Text)));
            //}
            //catch
            //{
            //    MessageBox.Show("Check your entry");
            //}
        }


    }
}